import { tags, request, summary, description, prefix, query } from 'koa-swagger-decorator'

import SMSService from '../utils/Sms'

const tag = tags(['Sms'])

@prefix("/sms")
export default class SmsController {

  @request("get", "/send")
  @summary("发送短信")
  @description("发送短信")
  @tag
  @query({
    phone: { type: 'string', required: true, description: '手机号' }
  })
  async sendSms (ctx) {
    const { phone } = ctx.request.query;

    let sms = new SMSService();
    try {
      let res = await sms.send(phone, "zhenghui", "123456");
      ctx.success(res, res ? '发送成功' : '发送失败');
    } catch (e) {
      ctx.fail(400, e.message);
    }

  }
}
